@page
@using EasyAbp.EShop.Plugins.Promotions.Permissions
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using EasyAbp.EShop.Plugins.Promotions.Localization
@using EasyAbp.EShop.Plugins.Promotions.Web.Menus
@model EasyAbp.EShop.Plugins.Promotions.Web.Pages.EShop.Plugins.Promotions.Promotions.Promotion.IndexModel
@inject IPageLayout PageLayout
@inject IHtmlLocalizer<PromotionsResource> L
@inject IAuthorizationService Authorization
@{
    PageLayout.Content.Title = L["Promotion"].Value;
    PageLayout.Content.BreadCrumb.Add(L["Menu:Promotion"].Value);
    PageLayout.Content.MenuItemName = PromotionsMenus.Promotion;

    var cardTitle = L["Promotion"].Value;

    if (Model.StoreName != null)
    {
        cardTitle += $" - {Model.StoreName}";
    }
}

@section scripts
{
    <abp-script src="/Pages/EShop/Plugins/Promotions/Promotions/Promotion/index.js"/>
}

@section styles
{
    <abp-style src="/Pages/EShop/Plugins/Promotions/Promotions/Promotion/index.css"/>
}

<script>
let storeId = '@Model.StoreId'
</script>

<abp-card>
    <abp-card-header>
        <abp-row>
            <abp-column size-md="_6">
                <abp-card-title>@cardTitle</abp-card-title>
            </abp-column>
            <abp-column size-md="_6" class="text-end">
                @if (await Authorization.IsGrantedAsync(PromotionsPermissions.Promotion.Create))
                {
                    <abp-dropdown>
                        <abp-dropdown-button text="@L["CreatePromotion"].Value" icon="plus" button-type="Primary"/>
                        <abp-dropdown-menu>
                            @foreach (var promotionType in Model.PromotionTypes.Values)
                            {
                                <abp-dropdown-item href="#" class="NewPromotionButton" promotion-type="@promotionType.Name">@promotionType.DisplayName</abp-dropdown-item>
                            }
                        </abp-dropdown-menu>
                    </abp-dropdown>
                }
            </abp-column>
        </abp-row>
    </abp-card-header>
    <abp-card-body>
        <abp-row class="mb-3">
            <a abp-collapse-id="PromotionCollapse" class="text-secondary">@L["TableFilter"] </a>
        </abp-row>
        <abp-collapse-body id="PromotionCollapse">
            <abp-dynamic-form abp-model="PromotionFilter" id="PromotionFilter" required-symbols="false"/>
            <hr/>
        </abp-collapse-body>
        <abp-table striped-rows="true" id="PromotionTable" class="nowrap"/>
    </abp-card-body>
</abp-card>